package com.DAO;

import com.Util.Sql;
import com.Module.RoomType;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class Roomtypeinfo implements Sql {
    public List<RoomType> list=new ArrayList<>();
    @Override
    public void select() {
        DatabaseConnection databaseConnection=new DatabaseConnection();
        try {
            Connection connection=databaseConnection.getconn("hotel","root","");
            Statement statement=connection.createStatement();
            String sql="select * from  roomtype";
            ResultSet resultSet=statement.executeQuery(sql);
            while (resultSet.next()){
                String  roomtype =resultSet.getString("roomtype");
                int bednumber =resultSet.getInt("bednumber");
                double price =resultSet.getDouble("price");
                RoomType room=new RoomType(roomtype,bednumber,price);
                list.add(room);
            }
            databaseConnection.release(connection,statement,resultSet);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public List<Object> select(String id) {
        return null;
    }

    @Override
    public int update() {
        return 0;
    }

    @Override
    public int update(Object obj) {
        DatabaseConnection databaseConnection=new DatabaseConnection();
        int ans = 0;
        try {
            Connection connection=databaseConnection.getconn("hotel","root","");
            Statement statement=connection.createStatement();
            RoomType roomType=(RoomType) obj;
            String sql="INSERT INTO roomtype VALUES('"+ roomType.getRoomtype()+"',+"+ roomType.getBednumber()+","+ roomType.getPrice() +")";
            ans=statement.executeUpdate(sql);
            databaseConnection.release(connection,statement);
        }catch (Exception e){
            e.printStackTrace();
        }
        return ans;
    }

    @Override
    public int delete(Object obj) {
        return 0;
    }



    @Override
    public int modify(Object obj) {
        return 0;
    }
}
